﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Core.DAL;
using Core;

namespace xManagerWebApp.__AdminCompany
{
    public partial class WUC_IndexExpenseChain : System.Web.UI.UserControl
    {      


        public Guid? SelectedChain
        {
            get
            {
                if (ViewState["SelectedChain"] != null)
                    return (Guid?)ViewState["SelectedChain"];
                else
                    return null;
            }
            set { ViewState["SelectedChain"] = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DropDownChainList.Items.Add(new ListItem("----------", ""));

                using (DataAccessLayer dc = new DataAccessLayer())
                {
                    var query = from exp in dc.DataContext.Chains
                                orderby exp.Name
                                select exp;

                    foreach (Chain c in query)
                        DropDownChainList.Items.Add(new ListItem(c.Name, c.Id.ToString()));

                }
            }
        }

        protected void LoadChain(object sender, EventArgs e)
        {
            if (DropDownChainList.SelectedIndex > 0)
            {
                Guid g = new Guid(DropDownChainList.SelectedValue);
                this.ViewExpenseChain.ChainID = g;
                this.SelectedChain = g;
            }
            else
            {
                this.ViewExpenseChain.ChainID = default(Guid);
                this.SelectedChain = default(Guid);
            }

        }
    }
}